﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLKDS.DAL;
using DevExpress.XtraEditors.DXErrorProvider;
using DevExpress.XtraEditors.Controls;
using QLKDS.DTO;

namespace QLKDS.Forms
{
    public partial class frmAbsentEdit : XtraForm
    {
        #region Properties
        private AbsentManager absentManager;
        private EmployeeManager employeeManager = new EmployeeManager();
        public AbsentInfo Absent;
        #endregion

        #region Methods


        /// <summary>
        /// Clear all Textboxes on this form
        /// </summary>
        private void ClearTextBoxes()
        {
            //this.txtCode.Text = String.Empty;
            //this.txtName.Text = String.Empty;
            //this.txtDiscountRetail.Text = String.Empty;
            //this.txtSchool.Text = String.Empty;
            //this.txtDescription.Text = String.Empty;
            //this.dteCreatedDate.DateTime = DateTime.Now;
            //this.dteCreatedDate.Properties.MaxValue = DateTime.Now;
            //this.txtName.Focus();
        }
        #endregion

        #region Init form
        public frmAbsentEdit()
        {
            InitializeComponent();
            this.absentManager = new AbsentManager();
            this.Load_info();
      
        }

        public void Load_info()
        {

            this.lueEmployee.Properties.DataSource = employeeManager.ListEmployee();
            this.lueEmployee.Properties.DisplayMember = "Fullname";
            this.lueEmployee.Properties.ValueMember = "Id";

            this.dteDate.DateTime = DateTime.Now;
        }

    




        private void frmAbsentEdit_Load(object sender, EventArgs e)
        {
            this.ClearTextBoxes();
            this.txtReason.Text = Absent.Reason;
            this.dteDate.DateTime = DateTime.Now;
        }
        #endregion

        #region Validate

     
        private void lueEmployee_EditValueChanged(object sender, EventArgs e)
        {
            if (this.lueEmployee.Text.Trim() == String.Empty)
            {
                //
            }
            else
            {
                this.dxepEmployee.ClearErrors();
            }
        }

       
      

        #endregion

        #region Button_click
        private void btnClear_Click(object sender, EventArgs e)
        {
            this.ClearTextBoxes();
        }
       
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.lueEmployee.Text.Trim() == String.Empty)
            {
                this.dxepEmployee.SetError(this.lueEmployee, "Lựa chọn nhân viên");
                return;
            }         
            else
            {       
                this.dxepEmployee.ClearErrors();
                          
            }


            /*****************************************************************/
            // Save employeeManager into database                   
            var absent = new Absent();
            absent.Id = Absent.Id;
            absent.EmployeeId = (int)this.lueEmployee.EditValue;
            absent.Reason = this.txtReason.Text.Trim();
            absent.Date = this.dteDate.DateTime;

            this.absentManager.UpdateAbsent(absent);
            // save employeeManager

         
            XtraMessageBox.Show("Dữ liệu thêm thành công.Tiếp tục thêm ?");
            this.DialogResult = DialogResult.OK;
                this.Close();
           
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        #endregion

   



    





      

 

      

     
        


    }
}
